// pages/print/zipPage/zipPage.js
var utils = require("../../../utils/utils.js");
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        chooseid:Number
    },
    chooseOk(e){
        var index = e.currentTarget.dataset.index;
        if(index==0){
            wx.navigateBack()
        }else{
            if(this.data.chooseid>=0){
                var file = this.data.list[this.data.chooseid].downUrl
                var name = this.data.list[this.data.chooseid].name
                // this.zipUploadFile(name,file)
                var reg = /^.*\.(?:xls|xlsx)$/i;
                if(reg.test(name)){
                  this.excelTpdf(file,name)
                }else{
                  //非excel
                //    wx.showLoading()
                   this.selectComponent("#loading").showLoadingCus();
                   this.zipUploadFile(name,file)
                }
            }else{
                utils.toast("请先选择打印文件")
            }
        }
    },
      //excel转pdf
  excelTpdf(path,name) {
    var that = this;
    that.selectComponent("#loading").showLoadingCus();
    utils.getSheetByUrl(name,path,function (res) {
       var data = res.data.data
    //    wx.hideLoading()
     that.selectComponent("#loading").hideLoadingCus();
       wx.navigateTo({
        url: '/pages/print/chooseSheet/chooseSheet?list='+escape(JSON.stringify(data))+'&serviceMainId='+that.data.serviceMainId+'&serviceSubtypeId='+that.data.serviceSubtypeId+'&tagFloor='+that.data.tagFloor+'&code='+that.data.code+'&zip=1',
      })
    })
  },
    zipUploadFile(name,fileUrl){
        var that = this;
        utils.uploadfile('',name,fileUrl,'','',function (res) {
            var data = res.data.data
            // wx.hideLoading()
             that.selectComponent("#loading").hideLoadingCus();
            wx.setStorageSync('isZip',name)
            // console.log(wx.setStorageSync('isZip',name))
            wx.navigateTo({
            url: '../list/list?code=' + that.data.code + '&name=' + data.localName + '&path=' + data.printUrl + '&pageNum=' + data.pageTotal +'&fileUrl='+data.fileUrl+'&serviceMainId='+that.data.serviceMainId+'&serviceSubtypeId='+that.data.serviceSubtypeId+'&tagFloor='+that.data.tagFloor+'&orientation='+data.orientation
            })
         })
    },
    chooseFile(e){
        var index = e.currentTarget.dataset.index;
        this.setData({
            chooseid:index
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this;
        wx.getSystemInfo({
            success: (result) => {
                var model = result.model;
                if (model == 'iPhone X') {
                    that.setData({
                        pdbottom: '68',
                    })
                } else {
                    that.setData({
                        pdbottom: '40'
                    })
                }
            },
        })
        that.setData({
            showList:options.succ,
            name:options.name,
            serviceMainId: options.serviceMainId,
            code: options.code,
            serviceSubtypeId: options.serviceSubtypeId,
            tagFloor: options.tagFloor
        })
        if(utils.is_define(options.list)){
            var list = JSON.parse(unescape(options.list))
            that.setData({
                list:list
            })
        }else{
            that.setData({
                list:[]
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    }
})